#pragma once

#include"Common.h"

class BuildTask
{
public:
	BuildTask()
		:_buildTilePosition(-1 , -1),
		_buildPosition(-1 , -1),
		_targetGeyser(NULL),
		_baseIndex(-1),
		_whatToBuild(UnitTypes::None)
	{
	}
	void Set(const TilePosition& buildTile , const int& baseIndex , const UnitType& whatToBuild)
	{
		_buildTilePosition = buildTile;
		_baseIndex = baseIndex;
		_whatToBuild = whatToBuild;

		if(whatToBuild == UnitTypes::Zerg_Extractor)
		{
			_buildPosition = Position((buildTile.x() - 1) * TILE_SIZE , buildTile.y() * TILE_SIZE);
			for each(Unit* whichUnit in Broodwar->getUnitsOnTile(buildTile.x() , buildTile.y()))
			{
				if(whichUnit->getType() == UnitTypes::Resource_Vespene_Geyser)
				{
					_targetGeyser = whichUnit;
					break;
				}
			}
		}
		else
		{
			int xOffset = (int)((float)whatToBuild.tileWidth() * 0.5) * TILE_SIZE;
			int yOffset = (int)((float)whatToBuild.tileHeight() * 0.5) * TILE_SIZE;
			_buildPosition = Position(buildTile.x() * TILE_SIZE + xOffset , buildTile.y() * TILE_SIZE + yOffset);
			_targetGeyser = NULL;
		}
	}
	bool NoTask() const
	{
		return _whatToBuild == UnitTypes::None;
	}
	UnitType GetBuildType() const
	{
		return _whatToBuild;
	}
	TilePosition GetBuildTile() const
	{
		return _buildTilePosition;
	}
	Position GetBuildPosition() const
	{
		return _buildPosition;
	}
	int GetBaseIndex() const
	{
		return _baseIndex;
	}
	Unit* GetGeySer() const
	{
		return _targetGeyser;
	}
private:
	TilePosition _buildTilePosition; 
	Position _buildPosition;
	Unit* _targetGeyser;
	int _baseIndex;
	UnitType _whatToBuild;
};